//
//  YZInputView.m
//  CocoaAsyncSocketClient
//
//  Created by lixiaoyi on 2018/6/20.
//  Copyright © 2018年 lixiaoyi. All rights reserved.
//

#import "YZInputView.h"

@implementation YZInputView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        //inputTextField
        CGRect tfFrame = CGRectMake(20, 5, frame.size.width - 100 - 20, frame.size.height - 10);
        self.inputTextField = [[UITextField alloc] initWithFrame:tfFrame];
        self.inputTextField.borderStyle = UITextBorderStyleRoundedRect;
        self.inputTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
        [self addSubview:self.inputTextField];
        
        // sendBtn
        CGRect btnFrame = CGRectMake(frame.size.width - 80, 5, 60, frame.size.height - 10);
        self.sendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.sendBtn.frame = btnFrame;
        self.sendBtn.backgroundColor = [UIColor colorWithRed:237.0/255.0 green:237.0/255.0 blue:237.0/255.0 alpha:1.0];
        [self.sendBtn setTitle:@"发送" forState:UIControlStateNormal];
        [self.sendBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.sendBtn.layer.cornerRadius = 4.0f;
        self.sendBtn.layer.masksToBounds = YES;
        self.sendBtn.layer.borderWidth = 1.0f;
        [self.sendBtn addTarget:self action:@selector(sendBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.sendBtn];
    }
    
    return self;
}

- (void)sendBtnClick:(UIButton *)sender {
    NSString *message = self.inputTextField.text;
    if (self.sendBtnBlock || message.length>0 ) {
        self.sendBtnBlock(message);
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
